package com.dongdongshop.service.impl;

import com.dongdongshop.common.PageResult;
import com.dongdongshop.mapper.TbBrandMapper;
import com.dongdongshop.pojo.TbBrand;
import com.dongdongshop.service.TbBrandService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
@DubboService
public class TbBrandServiceImpl implements TbBrandService {

    @Resource
    private TbBrandMapper tbBrandMapper;

    @Override
    public PageResult<TbBrand> selectInfoLimitServer(TbBrand brand, Integer pageNumber, Integer pageSize) {
        PageHelper.startPage(pageNumber,pageSize);
        List<TbBrand> list = tbBrandMapper.selectByExample(null);
        PageInfo<TbBrand> page = new PageInfo<>(list);
        PageResult<TbBrand> pageResult = new PageResult<>(page.getTotal(),page.getList());
        return pageResult;
    }

    @Override
    public List<TbBrand> selectAll() {
        List<TbBrand> tbBrands = tbBrandMapper.selectByExample(null);
        return tbBrands;
    }

    @Override
    public int addBrand(TbBrand brand) {
        return tbBrandMapper.insert(brand);
    }
}
